package Leo.websocket;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.web.socket.adapter.AbstractWebSocketSession;
import org.springframework.web.socket.config.annotation.*;
import org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor;

@Configuration
@EnableWebSocket
public class BaseWebsocketConfigurer implements  WebSocketConfigurer {
    @Autowired
    BaseWebsocketHandler baseWebsocketHandler;

    @Autowired
    AdditionWebsocketHandler additionWebsocketHandler;

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry webSocketHandlerRegistry) {
        //addHandler用于添加处理器、endPoint、拦截器。
        // 还有一个很重要的，setAllowedOrigins()用于设置允许访问此websocket的外部地址清单，例如"http://localhost:8080"，全允许则填入*
        webSocketHandlerRegistry.addHandler(baseWebsocketHandler,"/socket/*").addInterceptors(new BaseInterceptor()).setAllowedOrigins("*");
//        webSocketHandlerRegistry.addHandler(additionWebsocketHandler,"/adSocket");
    }
}
